//
//  MenuController.m
//  newView
//
//  Created by yjl on 13-1-2.
//  Copyright (c) 2013年 上海傲融软件公司. All rights reserved.
//

#import "MenuController.h"

@interface MenuController ()

@end

@implementation MenuController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSArray *items1 = [[NSArray alloc] initWithObjects:@"成都",@"邛崃",@"都江堰", nil];
    NSArray *items2 = [[NSArray alloc] initWithObjects:@"西安",@"宝鸡",@"延安", nil];
    NSArray *items3 = [[NSArray alloc] initWithObjects:@"长沙",@"张家界",@"岳阳", nil];
    
    self.datas  = [NSDictionary dictionaryWithObjectsAndKeys:
                  items1,@"四川",
                  items2,@"陕西",
                  items3,@"湖南",nil];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];
    
    // Step 1: Check to see if we can reuse a cell from a row that has just rolled off the screen
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    // Step 2: If there are no cells to reuse, create a new one
    if(cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    
    // Add a detail view accessory
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    // Step 3: Set the cell text
    cell.textLabel.text = [[self.datas objectForKey:[[self.datas allKeys]objectAtIndex:section]]objectAtIndex:row];
    
    // Step 4: Return the cell
    return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[self.datas allKeys]objectAtIndex:section];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[self.datas objectForKey:[[self.datas allKeys]objectAtIndex:section]] count];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.datas count];
}

@end
